package FenxiaoService

import (
	"context"
	"gdshop-back-end-go/common/response/FenxiaoResp"
)

// GetUserInfoAndGoodsRateByFenxiaoUserId
// level = 1 时 应该是自购的
func GetUserInfoAndGoodsRateByFenxiaoUserId(ctx context.Context, fenxiaoUserId, level, goodsId int) *FenxiaoResp.UserInfo {
	fuModel, err := GetFenxiaoUserModelByFenxiaoUserId(ctx, fenxiaoUserId)
	if err != nil {
		return nil
	}
	if fuModel == nil {
		return nil
	}
	var rate float64
	fglModel, err := GetGoodsLevel(ctx, goodsId, fuModel.LevelId)
	if err != nil {
		return nil
	}
	switch level {
	case 3:
		rate = float64(fglModel.ThreeRate) / 100000.00
		break
	case 2:
		rate = float64(fglModel.TwoRate) / 100000.00
		break
	case 1:
		rate = float64(fglModel.OneRate) / 100000.00
		break
	default:
		rate = float64(fglModel.OneRate) / 100000.00
		break
	}
	return &FenxiaoResp.UserInfo{
		Rate:          rate,
		LevelId:       fuModel.LevelId,
		FenxiaoUserId: fenxiaoUserId,
		MemberId:      fuModel.MemberId,
		Status:        fuModel.Status,
	}
}
